function login(){
    email=$('#email').val();
    password=$('#password').val();
    $.ajax({
	url: BASE_URL+"ajax/login",
        dataType: 'json',
        data: {
            'email':email,
            'password':password
        },
	type: "POST",
	success :function(data){
            if (data.login != true) alert(data.message);
            else
                {
                    location.reload();
                }
        }
    })
}
function login_enter(event){
    if (event.keyCode == 13)
        login();
}
function captcha(){
    $.ajax({
        url: BASE_URL+"ajax/captcha",
        dataType: 'json',
        success : function(data){
            $('#regcaptchaimg').html(data.captimg+"&nbsp;&nbsp;<img src='"+BASE_URL+"icons/reload.jpg' name='reloadcaptcha' id='reloadcaptcha' onclick='captcha()' />");
        }
    })
}

function hidedescription(){
    $.ajax({
        success : function(){
            $('#descriptionbox').html('');
        }
    })
}

function showdescription(){
    $.ajax({
        success : function(){
            $('#descriptionbox').html('<td class="Rgslb">Miêu tả bản thân</td> <td><textarea name="description" id="description" cols="60" rows=6></textarea></td>');
        }
    })
}

function register(){
    if($('#usertypeuser').attr('checked'))
        usertype    =   $('#usertypeuser').val();
    else usertype   =   $('#usertypeteacher').val();
    email       =   $('#regemail').val();
    password    =   $('#regpassword').val();
    firstname   =   $('#firstname').val();
    lastname    =   $('#lastname').val();
    address     =   $('#address').val();
    gender      =   $('#gender').val();
    phone       =   $('#phone').val();
    bdd         =   $('#bdd').val();
    bdm         =   $('#bdm').val();
    bdy         =   $('#bdy').val();
    acceptcheck =   $('#accept').attr('checked');
    captword    =   $('#captword').val();
    captcha     =   $('#captcha').val();
    description =   $('#description').val();
    skype       =   $('#skype').val();
    
    $.ajax({
	url: BASE_URL+"ajax/register",
        dataType: 'json',
        data: {          
            'usertype'   :   usertype,
            'email'      :   email,
            'password'   :   password,
            'firstname'  :   firstname,
            'lastname'   :   lastname,
            'address'    :   address,
            'gender'     :   gender,
            'phone'      :   phone,
            'skype'      :   skype,
            'bdd'        :   bdd,
            'bdm'        :   bdm,
            'bdy'        :   bdy,
            'description':   description,
            'captcha'    :   captcha
        },
	type: "POST",
	success :function(data){
            switch(data.error){
                case 1:$('#captchareport').html('<div class="wrong" id="captchareport">'+data.message+'</div>'); 
                  $.ajax({
                        url: BASE_URL+"ajax/captcha",
                        dataType: 'json',
                        success : function(data){
                            $('#regcaptchaimg').html(data.captimg+"&nbsp;&nbsp;<img src='"+BASE_URL+"icons/reload.jpg' name='reloadcaptcha' id='reloadcaptcha' onclick='captcha()' />");
                        }
                  });
                        break;
                case 2:$('#bdyreport').html(data.message); break;
                case 3:$('#regBox').html(data.message); break;
                case 4:$('#emailreport').html(data.message); break;
                default:$('#regBox').html(data.message);
                         break;
            }
        }
    })
}
function changeimage(link){
	$("#newsAvatar").attr("src",link).attr("height","130px").attr("width","130px");
}
